home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94c.txt / 000043_mslamm@pluto.mscc.huji.ac.il _Wed Dec 28 20:32:06 1994.msg < prev    next >
Internet Message Format  |  1995-02-09  |  3KB

  1. Received: from optima.CS.Arizona.EDU by cheltenham.CS.Arizona.EDU; Wed, 28 Dec 1994 11:32:20 MST
  2. Received: from pluto.mscc.huji.ac.il by optima.CS.Arizona.EDU (5.65c/15) via SMTP
  3.     id AA21911; Wed, 28 Dec 1994 11:32:15 MST
  4. Received: by pluto.mscc.huji.ac.il (AIX 3.2/UCB 5.64/4.03)
  5.           id AA50464; Wed, 28 Dec 1994 20:32:06 +0200
  6. Date: Wed, 28 Dec 1994 20:32:06 +0200 (WET)
  7. From: Zvi Lamm <mslamm@pluto.mscc.huji.ac.il>
  8. To: swampler@noao.edu
  9. Cc: icon-group@cs.arizona.edu
  10. Subject: Re: Truth-Table generator
  11. In-Reply-To: <9412281815.AA15224@orpheus.gemini.edu>
  12. Message-Id: <Pine.A32.3.91.941228203008.42611B-100000@pluto.mscc.huji.ac.il>
  13. Mime-Version: 1.0
  14. Content-Type: TEXT/PLAIN; charset=US-ASCII
  15.  
  16.  
  17.  
  18. On Wed, 28 Dec 1994 swampler@noao.edu wrote:
  19.  
  20. > > I had a need to write a program to output truth tables for boolean
  21. > > expressions. I used the programmming language J (a sister of APL). The
  22. > > 'program' was about two lines long.  I wrote a program for the same task
  23. > > in Icon. I include it below.  This Icon solution is ugly (because of the
  24. > > programmer, not the language..), but works. I would be happy to hear
  25. > > comments. Any idea for improvemnet is welcome.
  26. > >
  27. > > I got alot of help on comp.lang.apl when writing the J version - so don't
  28. > > let me down! I think I will write a short note comparing the solutions.
  29. > > My idea is to show the way different languages shape your thought. Both J
  30. > > and Icon are rather special in that they give the programmer tools not
  31. > > found in other languages. Does this interest anyone?
  32. > Well, I managed to delete your original program, but here's one that's probably
  33. > similar, using generators rather than vectors.  Can it be adapted to your case?
  34. >    procedure main()
  35. >       local t1, t2
  36. >       every (t1 := (0|1)) & (t2 := (0|1)) do {
  37. >          every writes(format ( t1 | t2 |          # variables
  38. >                               "|" |              # separator
  39. >                               iand(t1,t2) | ior(t1,t2) |  # functions
  40. >                               ixor(t1,t2)
  41. >                      ))
  42. >          write()
  43. >          }
  44. >    end
  45. >    procedure format(t)
  46. >       # pretty up things for output, the 'wide' field width (5 characters)
  47. >       #   would let this be used to produce a table header, as in:
  48. >       #
  49. >       #     every writes(format("A" | "B" | "" | "A&B" | "A|B" | "A^B"))
  50. >       #     write()
  51. >       #
  52. >       #   though the above main program doesn't do so...
  53. >       # since this is a one-liner, it could be embedded in place of the call
  54. >       #   above, but that would be ugly!
  55. >       return center(map(t, "01", "FT"), 5)
  56. >    end
  57.  
  58. I rather wanted an all generator solution myself. But the problem is that 
  59. my truth tables ma have more than two variables (t1 and t2, above). Now 
  60. this makes it a bit harder to do it like this...
  61.  
  62. Ehud